package com.scalar.forecast.forecastEntry.actions;

import com.scalar.forecast.ForecastExtendedAction;
import com.scalar.forecast.commons.Constants;
import com.scalar.forecast.forecastEntry.actionCommands.ForecastEntryBuildActionCommandFactory;
import com.scalar.forecast.forecastEntry.forms.ForecastEntryForm;
import com.scalar.forecast.actionCommands.ActionCommand;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * User: Sujan Kumar
 * Date: Feb 18, 2005
 * Time: 4:01:29 PM
 */
public class ForecastEntryBuildAction extends ForecastExtendedAction
{
     public ActionForward executeRequest( ActionMapping mapping,
                                                      ActionForm form,
                                                      HttpServletRequest request,
                                                      HttpServletResponse response) throws Exception
    {
        ActionForward actionForward = mapping.findForward ( "forecastEntryBuild" );
        String action = request.getParameter ( "action" );
        request.setAttribute ( Constants.FORECAST_IS_BUILD, "true" );
        try
        {
            if ( action == null )
            {
                action = ACTION_SEARCH;
            }
            ForecastEntryForm forecastEntryForm = ( ForecastEntryForm ) form;

            forecastEntryForm.setBuild( true );
            ActionCommand actionCommand = ForecastEntryBuildActionCommandFactory.getActionCommand( action );
            if ( actionCommand != null)
            {
                actionForward = actionCommand.execute( mapping, form, request, response );
            }
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
        return actionForward;
    }

}
